package awd;

import org.beetl.core.resource.ClasspathResourceLoader;
import org.beetl.ext.spring.BeetlGroupUtilConfiguration;
import org.beetl.ext.spring.BeetlSpringViewResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;

@SpringBootApplication
@EnableDiscoveryClient
@Configuration
@EnableHystrix
@EnableFeignClients
public class JlsSyjdWebApplication implements CommandLineRunner {

	private  String appcode="eyJ0eXBlIjoiYXBwIiwid2lkdGgiOiIiLCJoZWlnaHQiOiIiLCJjb250ZW50IjoiY29yZS5rc3NRdHN5KCk7In0=";
	public static void main(String[] args) {
		SpringApplication.run(JlsSyjdWebApplication.class, args);
	}

	@Autowired
	void setEnviroment(Environment env) {
		System.out.println("my-config.appName from env: " + env.getProperty("spring.application.name"));
	}

	@Bean
	public CacheManager cacheManager() {
		return new ConcurrentMapCacheManager("entities");
	}

	@Bean(initMethod = "init", name = "beetlConfig")
	public BeetlGroupUtilConfiguration getBeetlGroupUtilConfiguration() {
		BeetlGroupUtilConfiguration beetlGroupUtilConfiguration = new BeetlGroupUtilConfiguration();
		ResourcePatternResolver patternResolver = ResourcePatternUtils
				.getResourcePatternResolver(new DefaultResourceLoader());
			try {
			ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(
					this.getClass().getClassLoader(), "/templates");
			beetlGroupUtilConfiguration.setResourceLoader(resourceLoader);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// 读取配置文件信息
		return beetlGroupUtilConfiguration;
	}

	@Bean(name = "beetlViewResolver")
	public BeetlSpringViewResolver getBeetlSpringViewResolver() {
		BeetlSpringViewResolver beetlSpringViewResolver = new BeetlSpringViewResolver();
		beetlSpringViewResolver.setPrefix("/");
		beetlSpringViewResolver.setSuffix(".html");
		beetlSpringViewResolver.setContentType("text/html;charset=UTF-8");
		beetlSpringViewResolver.setOrder(0);
		beetlSpringViewResolver.setConfig(getBeetlGroupUtilConfiguration());
		return beetlSpringViewResolver;
	}

	@Override
	public void run(String... args) throws Exception {
		System.out.println(">>>>>>>>>>>>>>收押岗位App 初始化应用参数<<<<<<<<<<<<<");
		
		System.out.println(">>>>>>>>>>>>>>收押岗位App 初始化应用菜单<<<<<<<<<<<<<");
		System.out.println(">>>>>>>>>>>>>>收押岗位App 初始化应用菜单结束<<<<<<<<<<<<<");
		System.out.println(">>>>>>>>>>>>>>收押岗位App 启动结束<<<<<<<<<<<<<");
	}
	
	
}
